package myPetStore.web.servlet;

import myPetStore.domain.Account;
import myPetStore.domain.Cart;
import myPetStore.domain.Order;
import myPetStore.domain.Sequence;

import javax.servlet.ServletException;
import javax.servlet.SessionCookieConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class NewOrderFormServlet extends HttpServlet {
    private static final String  NEW_ORDER_FORM="/WEB-INF/jsp/order/newOrder.jsp";
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //判断是否登录
        HttpSession session=req.getSession();
        Account loginAccount=(Account) session.getAttribute("loginAccount");
        if(loginAccount==null){
            resp.sendRedirect("signonForm");
        }else{
            String creditCardTypes="sfz";
            session.setAttribute("creditCardType",creditCardTypes);
            Cart cart=(Cart)session.getAttribute("cart");
            Order order=new Order();
            order.initOrder(loginAccount,cart);
            session.setAttribute("order",order);
            req.getRequestDispatcher(NEW_ORDER_FORM).forward(req,resp);
        }
    }
}
